package cn.dglydrpy.study.spring.ioc;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.context.event.ContextStoppedEvent;
import org.springframework.stereotype.Component;


/**
 * @Description:  
 * @author:LY_飘涯
 * @date:2019年6月5日 下午6:13:47 
 * @version:1.0
 */
@Component
public class MyListener implements ApplicationListener<ApplicationEvent>{

	@Override
	public void onApplicationEvent(ApplicationEvent event) {
	    if (event instanceof ContextRefreshedEvent) {
            System.out.println("---------- ContextRefreshedEvent: 当ApplicationContext初始化或者刷新时触发应用刷新 ----------");
        } else if (event instanceof ContextStartedEvent) {
        	System.out.println("---------- ContextStartedEvent: 容器调用ConfigurableApplicationContext的Start()方法开始/重新开始容器时触发应用启动 ----------");
        } else if (event instanceof ContextStoppedEvent) {
        	System.out.println("---------- ContextStoppedEvent: 容器调用ConfigurableApplicationContext的Stop()方法停止容器时触发应用停止 ----------");
        } else if (event instanceof ContextClosedEvent) {
        	System.out.println("---------- ContextClosedEvent: ApplicationContext被关闭时触发应用关闭,其管理的所有单例Bean都被销毁 ----------");
        }
	}

}
